package com.joker.excel.rest;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.joker.excel.Listener.DemoDataListener;
import com.joker.excel.bean.bo.ExcelBo;
import com.joker.excel.service.ExcelService;
import com.joker.excel.utils.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.*;

@Api(tags = "excel工具")
@RestController
@RequestMapping(value = "/excelUtil")
public class ExcelUtilController {
    @Autowired
    ExcelService excelService;

    @ApiOperation(value = "上传excel文件", tags = "上传excel文件", httpMethod = "POST")
    @PostMapping(value = "/upload")
    public String readExcel(MultipartFile file,String ruleId) {
        if (Objects.isNull(file)) {
            System.out.println("文件为空");
        }
        excelService.calculate(file);

        return "读取完成";
    }

    @ApiOperation(value = "下载excel文件", tags = "下载excel文件", httpMethod = "POST")
    @PostMapping(value = "/downLoad")
    public void downLoadExcel() {

    }

    @ApiOperation(value = "获取匹配规则", tags = "获取匹配规则", httpMethod = "POST")
    @PostMapping(value = "/getRule")
    public Map getRule() {
        Map map = new HashMap();
        map.put("rule01","111111111");
        map.put("rule02","111111111");
        return map;
    }

}

